﻿using fuzhu;
using Microsoft.AspNetCore.Http;
using SqlSuarEntity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XXX.Common;
using XXX.Models;
using XXX.Models.AS;
using XXX.Models.XXXEntities;

namespace XXX.Bo
{
    public class U8DBHelp
    {
        

        /// <summary>
        /// 新增BOM(一个母件)
        /// </summary>
        public static string InsertBOM(List<ZDY_XINDI_BOMDR> li, string cMaker, string ConStr)
        {
            string acc = CanShu.cZT.IndexOf("@") < 0 ? CanShu.cZT : CanShu.cZT.Substring(CanShu.cZT.IndexOf("@") + 1, CanShu.cZT.Length - (CanShu.cZT.IndexOf("@") + 1));
            if (li == null || li.Count == 0)
            {
                return "无子集数据";
            }
            try
            {
                //同一个母件的不同子件插入临时表
                for (int i = 0; i < li.Count; i++)
                {
                    if (InsertBomdr(li[i], ConStr) == 0)
                    {
                        StoreBomdr(li[0].guid, ConStr);
                        return "数据插入BOM临时表失败";
                    }
                }
                //一个母件的BOM一次性新增
                if (daoruBOM("1", acc, cMaker, li[0].guid, ConStr) != "导入完成")
                {
                    StoreBomdr(li[0].guid, ConStr);
                    return "新增BOM失败";
                }
                StoreBomdr(li[0].guid, ConStr);
                return "";

            }
            catch (Exception exception)
            {
                StoreBomdr(li[0].guid, ConStr);
                return ("失败：" + exception.Message);
            }
        }

        /// <summary>
        /// 插入BOM临时表
        /// </summary>
        private static int InsertBomdr(ZDY_XINDI_BOMDR model, string ConStr)
        {
            string SQL = @"
insert into [zdy_xindi_bomdr](
      [guid]
      ,[mjbm]
      ,[opseq]
      ,[cinvcode]
      ,[baseqtyn]
      ,[define29]
      ,[define22]
      ,[remark]
      ,[opid]
      ,[wiptype]
      ,[effecdate]
      ,[version]
      ,[sortseq]
) VALUES (
      @guid
      ,@mjbm
      ,@opseq
      ,@cinvcode
      ,@baseqtyn
      ,@define29
      ,@define22
      ,@remark
      ,@opid
      ,@wiptype
      ,@effecdate
      ,@version
      ,@sortseq
)
";
            SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@guid",DbHelper.ToDbValue(model.guid)),
                    new SqlParameter("@mjbm",DbHelper.ToDbValue(model.mjbm)),
                    new SqlParameter("@opseq",DbHelper.ToDbValue(model.opseq)),
                    new SqlParameter("@cinvcode",DbHelper.ToDbValue(model.cinvcode)),
                    new SqlParameter("@baseqtyn",DbHelper.ToDbValue(model.baseqtyn)),
                    new SqlParameter("@define29",DbHelper.ToDbValue(model.define29)),
                    new SqlParameter("@define22",DbHelper.ToDbValue(model.define22)),
                    new SqlParameter("@remark",DbHelper.ToDbValue(model.remark)),
                    new SqlParameter("@opid",DbHelper.ToDbValue(model.opid)),
                    new SqlParameter("@wiptype",DbHelper.ToDbValue(model.wiptype)),
                    new SqlParameter("@effecdate",DbHelper.ToDbValue(model.effecdate)),
                    new SqlParameter("@version",DbHelper.ToDbValue(model.version)),
                    new SqlParameter("@sortseq",DbHelper.ToDbValue(model.sortseq))
                };

            return DbHelper2.ExecuteNonQuery(SQL, para, CommandType.Text, ConStr);
        }

        /// <summary>
        /// BOM临时表移出失效数据
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="ConStr"></param>
        /// <returns></returns>
        public static int StoreBomdr(string guid, string ConStr)
        {
            string SQL = @"
INSERT INTO [zdy_xindi_bomdr_bak]
  ([id],[guid],[mjbm],[opseq],[cinvcode],[baseqtyn],[define29],[define22]
  ,[remark],[opid],[wiptype],[effecdate],[version],[sortseq]
  ) SELECT
   [id],[guid],[mjbm],[opseq],[cinvcode],[baseqtyn],[define29],[define22]
  ,[remark],[opid],[wiptype],[effecdate],[version],[sortseq]
  FROM [zdy_xindi_bomdr] 
  WHERE [guid] = '{0}'

  DELETE FROM [zdy_xindi_bomdr] WHERE [guid] = '{0}'
";
            return DbHelper2.ExecuteNonQuery(string.Format(SQL, guid), ConStr);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="drfw">1 导入全部，2 只导入子件(先删除再导入）。</param>
        /// <param name="cacc">账套编码</param>
        /// <param name="cmaker">制单人</param>
        /// <param name="guid">本次导入的记录 </param>
        /// <param name="error"></param>
        /// <returns>导入完成</returns>
        private static string daoruBOM(string drfw, string cacc, string cmaker, string guid, string ConStr)
        {
            SqlParameter[] para = new SqlParameter[] {
                new SqlParameter("@drfw",SqlDbType.VarChar),
                new SqlParameter("@cacc",SqlDbType.VarChar),
                new SqlParameter("@cmaker",SqlDbType.VarChar),
                new SqlParameter("@guid",SqlDbType.VarChar),
                new SqlParameter("@error",SqlDbType.VarChar,1000)
            };
            int index = -1;
            para[++index].Value = drfw;
            para[++index].Value = cacc;
            para[++index].Value = cmaker;
            para[++index].Value = guid;
            para[++index].Direction = ParameterDirection.Output;

            DbHelper2.ExecuteNonQuery("zdy_xindi_sp_daoruBOM", para, CommandType.StoredProcedure, ConStr);
            return DbHelper.GetDbString(para[index].Value);
        }

        /// <summary>
        /// 生成生产订单
        /// </summary>
        /// <param name="dtMo">订单表头信息</param>
        /// <param name="dtOrderDetail">订单行</param>
        /// <param name="dtAllocate">订单子件</param>
        /// <returns></returns>
        public static string InsertMo(DataTable dtMo, DataTable dtOrderDetail, DataTable dtAllocate, string ConStr)
        {

            SqlTransaction tran = DbHelper2.BeginTrans(ConStr);
            try
            {
                //取单据号
                //DateTime ddt =Convert.ToDateTime(dtMo.Rows[0]["ddate"]);

                //int iyear = (Convert.ToInt32(ddt.Year) - 2000);
                //int imonth = Convert.ToInt32(ddt.Month);
                //int iday = Convert.ToInt32(ddt.Day);
                //string  cDate1 = iyear.ToString().PadLeft(2, '0') + imonth.ToString().PadLeft(2, '0') + iday.ToString().PadLeft(2, '0');

                //string sql = "select max(right(ccode,3))+1 from rdrecord32 where ccode like '"+cDate1+"%'";
                //string cCode = GenCode();
                //取得账套号
                string cAcc = CanShu.cZT.Substring(CanShu.cZT.Length - 3, 3);
                //id值减去获取条件，后续在新增
                int[] arrayMoid = GetIDOnTransaction("00", cAcc, "mom_order", 1, tran);
                int iMoid = arrayMoid[0] - 1;

                int cntOrderdetail = dtOrderDetail.Rows.Count;
                int[] arrayModid = GetIDOnTransaction("00", cAcc, "mom_orderdetail", cntOrderdetail, tran);
                int iModidf = arrayModid[0] - cntOrderdetail;
                int iModid = arrayModid[1] - cntOrderdetail; ;

                int cntAllocate = dtOrderDetail.Rows.Count;
                //int cntAllocate = dtAllocate.Rows.Count;
                int[] arrayAllocate = GetIDOnTransaction("00", cAcc, "mom_moallocate", cntAllocate, tran);
                int iAllocateidf = arrayAllocate[0] - cntAllocate;
                int iAllocateid = arrayAllocate[1] - cntAllocate; ;

                iMoid += 1;
                iModidf += 1;
                iModid += 1;
                iAllocateidf += 1;
                iAllocateid += 1;


                int iModidnew = 0;

                if (dtMo.Rows.Count > 0)
                {
                    //写数据库，刷新

                    string sql1 = @"  Insert Into mom_order(moid,mocode,createdate,createuser,updcount,VTid)
Values (@id,@mocode,getdate(),@createuser,@updcount,@VTid)";
                    DbHelper2.ExecuteSqlWithTrans(sql1, new SqlParameter[]{
                                         new SqlParameter("@id",iMoid+1000000000),
                                         new SqlParameter("@mocode",  dtMo.Rows[0]["mocode"]),
                                         new SqlParameter("@createuser", dtMo.Rows[0]["createuser"]),
                                         new SqlParameter("@updcount",dtMo.Rows[0]["updcount"]),
                                             new SqlParameter("@VTid",dtMo.Rows[0]["VTid"])
                    }, CommandType.Text, tran);

                    for (int i = 0; i < dtOrderDetail.Rows.Count; i++)
                    {
                        //iModidf += 1;
                        //iModid += 1;
                        iModidnew = iModid + DbHelper.GetDbInt(dtOrderDetail.Rows[i]["sortseq"]);


                        sql1 = @"INSERT Into dbo.mom_orderdetail(modid,moid,sortseq,MoClass,qty,MrpQty,SoType,sodid,socode,soseq,
Status,OrgStatus,bomid,RoutingId,CustBomId,DemandId,partid,invcode,AlloVTid,RelsAlloVTid,bomtype, mdeptcode,
RelsDate ,RelsUser,MoTypeId,OrderType,OrderDId,OrderCode,orderseq,Free1,AuxUnitCode) 
values(@modid,@moid,@SortSeq,1,@qty,@MrpQty,@SoType,@sodid,@socode,@soseq,
3,2,@bomid,0,0,@DemandId,@partid,@invcode,30417,30426,1,@mdeptcode,
@RelsDate ,@RelsUser,@MoTypeId,@OrderType,@OrderDId,@OrderCode,@orderseq,@free1,@AuxUnitCode) ";
                        DbHelper2.ExecuteSqlWithTrans(sql1, new SqlParameter[]{
                                         new SqlParameter("@modid",iModidnew+1000000000),
                                         new SqlParameter("@moid",iMoid+1000000000),
                                         new SqlParameter("@SortSeq",dtOrderDetail.Rows[i]["sortseq"]),
                                         new SqlParameter("@qty",dtOrderDetail.Rows[i]["qty"]),
                                         new SqlParameter("@MrpQty",dtOrderDetail.Rows[i]["qty"]),
                                          new SqlParameter("@mdeptcode",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["mdeptcode"])),
                                         new SqlParameter("@SoType",dtOrderDetail.Rows[i]["SoType"]),
                                         new SqlParameter("@sodid",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["sodid"])),
                                         new SqlParameter("@socode",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["socode"])),
                                         new SqlParameter("@soseq",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["soseq"])),
                                         new SqlParameter("@bomid",dtOrderDetail.Rows[i]["bomid"]),
                                         new SqlParameter("@DemandId",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["DemandId"])),
                                         new SqlParameter("@partid",dtOrderDetail.Rows[i]["partid"]),
                                         new SqlParameter("@invcode",dtOrderDetail.Rows[i]["invcode"]),
                                         new SqlParameter("@RelsDate",DateTime.Now.ToString("yyyy-MM-dd")),
                                         new SqlParameter("@RelsUser",dtMo.Rows[0]["createuser"]),
                                           new SqlParameter("@MoTypeId",dtOrderDetail.Rows[i]["MoTypeId"]),
                                             new SqlParameter("@OrderType",dtOrderDetail.Rows[i]["SoType"]),
                                               new SqlParameter("@OrderDId",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["sodid"])),
                                                 new SqlParameter("@OrderCode",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["socode"])),
                                                  new SqlParameter("@orderseq",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["soseq"])),
                                                  new SqlParameter("@free1",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["free1"])),
                                                  new SqlParameter("@AuxUnitCode",DbHelper.ToDbValue(dtOrderDetail.Rows[i]["AuxUnitCode"]))
                    }, CommandType.Text, tran);

                        if (DbHelper.GetDbDate(dtOrderDetail.Rows[i]["DueDate"]) < DbHelper.GetDbDate(dtOrderDetail.Rows[i]["StartDate"]))
                            dtOrderDetail.Rows[i]["DueDate"] = dtOrderDetail.Rows[i]["StartDate"];

                        //if ( DbHelper.GetDbDate(dtOrderDetail.Rows[i]["DueDate"]) <DateTime.Now)
                        //    dtOrderDetail.Rows[i]["DueDate"] = DateTime.Now;

                        sql1 = @"INSERT Into dbo.mom_morder(modid,StartDate,DueDate,moid) values(@modid,@StartDate,@DueDate,@moid) ";
                        DbHelper2.ExecuteSqlWithTrans(sql1, new SqlParameter[]{
                                         new SqlParameter("@modid",iModidnew+1000000000),
                                         new SqlParameter("@StartDate",dtOrderDetail.Rows[i]["StartDate"]),
                                         new SqlParameter("@DueDate",dtOrderDetail.Rows[i]["DueDate"]),
                                           new SqlParameter("@moid", iMoid+1000000000)
                    }, CommandType.Text, tran);

                        //插入子件表
                        DataRow[] drs = dtAllocate.Select(string.Format("sortseq = '{0}'", dtOrderDetail.Rows[i]["sortseq"]));

                        DataTable dt4 = dtAllocate.Clone();
                        foreach (DataRow dr in drs)
                        {
                            dt4.ImportRow(dr);//复制行数据到新表                
                        }
                        for (int j = 0; j < dt4.Rows.Count; j++)
                        {
                            iAllocateidf += 1;
                            iAllocateid += 1;
                            //SELECT AllocateId,modid,SortSeq,OpSeq,ComponentId,FVFlag,BaseQtyN,BaseQtyD,ParentScrap,CompScrap,qty,StartDemDate,EndDemDate,WIPType,ByproductFlag,QcFlag,Offset,InvCode,OpComponentId,ProductType,SoType,sodid,socode,soseq FROM dbo.mom_moallocate
                            sql1 = @"INSERT Into dbo.mom_moallocate(AllocateId,modid,SortSeq,OpSeq,ComponentId,FVFlag,BaseQtyN,BaseQtyD,
ParentScrap,CompScrap,qty,StartDemDate,EndDemDate,WIPType,ByproductFlag,QcFlag,Offset,InvCode,OpComponentId,ProductType,RequisitionFlag,
AuxUnitCode,ChangeRate,AuxBaseQtyN,AuxQty,UpperMoQty ) 
values(@AllocateId,@modid,@SortSeq,@OpSeq,@ComponentId,1,@BaseQtyN,1,
0,0,@qty,@StartDemDate,@EndDemDate,@WIPType,0,0,0,@InvCode,@OpComponentId,1,0,
@AuxUnitCode,@ChangeRate,@AuxBaseQtyN,@AuxQty,@UpperMoQty ) ";
                            DbHelper2.ExecuteSqlWithTrans(sql1, new SqlParameter[]{
                                         new SqlParameter("@modid",iModidnew+1000000000),
                                         new SqlParameter("@AllocateId",iAllocateid+1000000000),
                                         new SqlParameter("@SortSeq",(j+1)*10),
                                         new SqlParameter("@OpSeq",dt4.Rows[j]["OpSeq"]),
                                         new SqlParameter("@ComponentId",dt4.Rows[j]["ComponentId"]),
                                         new SqlParameter("@BaseQtyN",dt4.Rows[j]["BaseQtyN"]),
                                         new SqlParameter("@qty",dt4.Rows[j]["qty"]),
                                         new SqlParameter("@WIPType",dt4.Rows[j]["iwiptype"]),
                                         new SqlParameter("@StartDemDate",dtOrderDetail.Rows[i]["StartDate"]),
                                         new SqlParameter("@EndDemDate",dtOrderDetail.Rows[i]["DueDate"]),
                                         new SqlParameter("@InvCode",dt4.Rows[j]["InvCode"]),
                                         new SqlParameter("@OpComponentId",dt4.Rows[j]["OpComponentId"]),
                                          new SqlParameter("@AuxUnitCode",DbHelper.ToDbValue(dt4.Rows[j]["AuxUnitCode"])),
                                           new SqlParameter("@ChangeRate",DbHelper.ToDbValue(dt4.Rows[j]["ChangeRate"])),
                                            new SqlParameter("@AuxBaseQtyN",DbHelper.ToDbValue(dt4.Rows[j]["AuxBaseQtyN"])),
                                             new SqlParameter("@AuxQty",DbHelper.ToDbValue(dt4.Rows[j]["AuxQty"])),
                                              new SqlParameter("@UpperMoQty",dtOrderDetail.Rows[i]["qty"]),
                                         //new SqlParameter("@define29",dtOrderDetail.Rows[i]["ccusname"]),
                                         //new SqlParameter("@define30",dtOrderDetail.Rows[i]["lot"]),
                                         //new SqlParameter("@define35",dtOrderDetail.Rows[i]["ddsl"]),
                                         //new SqlParameter("@define37",dtOrderDetail.Rows[i]["jjjq"]),
                                         //new SqlParameter("@whcode",dt4.Rows[j]["cwhcode"]),
                                         //new SqlParameter("@lotno",dt4.Rows[j]["cbatch"])
                    }, CommandType.Text, tran);

                            //                            sql1 = @"INSERT Into dbo.mom_moallocate_extradefine(AllocateId,cbdefine9,cbdefine10,cbdefine11,cbdefine12) 
                            //select  @AllocateId,BaseQtyN,CompScrap,BaseQtyN/BaseQtyD*(1+CompScrap/100),b.description from bom_opcomponent  a
                            //left join mom_motype b on b.MoTypeId=@MoTypeId
                            //where OpComponentId=@OpComponentId ";
                            //                            DbHelper.ExecuteSqlWithTrans(sql1, new SqlParameter[]{ 
                            //                                         new SqlParameter("@AllocateId",iAllocateid+1000000000),  
                            //                                         new SqlParameter("@MoTypeId",dtOrderDetail.Rows[i]["MoTypeId"]),
                            //                                          new SqlParameter("@OpComponentId",dt4.Rows[j]["OpComponentId"])
                            //                    }, CommandType.Text, tran);

                        }

                    }

                    if (iModidnew > iModid)
                    {
                        iModid = iModidnew;
                    }
                }

                DbHelper2.CommitTransAndCloseConnection(tran);
                return "";
            }
            catch (Exception exception)
            {
                DbHelper2.RollbackAndCloseConnection(tran);
                return ("导入失败：" + exception.Message);
            }

        }

        /// <summary>
        /// 生产订单表头
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMoTable1()
        {
            //SELECT moid,mocode,createdate,createuser,updcount,VTid FROM dbo.mom_order
            DataTable table = new DataTable();
            table.Columns.Add("mocode", typeof(string));
            table.Columns.Add("createdate", typeof(DateTime));
            table.Columns.Add("createuser", typeof(string));
            table.Columns.Add("updcount", typeof(int));
            table.Columns.Add("VTid", typeof(int));
            return table;
        }

        /// <summary>
        /// 生产订单detail
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMoTable2()
        {
            //            SELECT modid,StartDate,DueDate,moid FROM dbo.mom_morder

            //SELECT modid,moid,sortseq,MoClass,qty,MrpQty,SoType,sodid,socode,soseq,Status,
            //            OrgStatus,bomid,RoutingId,CustBomId,DemandId,partid,invcode,AlloVTid,RelsAlloVTid FROM dbo.mom_orderdetail
            DataTable table = new DataTable();
            table.Columns.Add("StartDate", typeof(DateTime));
            table.Columns.Add("DueDate", typeof(DateTime));
            table.Columns.Add("SortSeq", typeof(string));
            table.Columns.Add("MoClass", typeof(string));
            table.Columns.Add("mdeptcode", typeof(string));
            table.Columns.Add("qty", typeof(decimal));
            table.Columns.Add("SoType", typeof(int));
            table.Columns.Add("sodid", typeof(int));
            table.Columns.Add("socode", typeof(string));
            table.Columns.Add("soseq", typeof(int));
            table.Columns.Add("DemandId", typeof(int));
            table.Columns.Add("bomid", typeof(int));
            table.Columns.Add("partid", typeof(int));
            table.Columns.Add("invcode", typeof(string));
            table.Columns.Add("AuxUnitCode", typeof(string));
            //table.Columns.Add("ccusname", typeof(string));
            //table.Columns.Add("lot", typeof(string));
            //table.Columns.Add("ddsl", typeof(Int32));
            //table.Columns.Add("jjjq", typeof(DateTime));
            //table.Columns.Add("cll", typeof(string));
            //table.Columns.Add("crk", typeof(string));

            table.Columns.Add("MoTypeId", typeof(int));
            table.Columns.Add("free1", typeof(string));
            return table;


            //cSource,SoDId,SoType,iMrpsid,csocode,irowno
        }

        public static DataTable GetMoTable3()
        {
            //    SELECT AllocateId,modid,SortSeq,OpSeq,ComponentId,FVFlag,BaseQtyN,BaseQtyD,
            //        ParentScrap,CompScrap,qty,StartDemDate,EndDemDate,WIPType,ByproductFlag,QcFlag,Offset,InvCode,OpComponentId,ProductType,SoType,sodid,socode,soseq FROM dbo.mom_moallocate

            DataTable table = new DataTable();
            table.Columns.Add("SortSeq", typeof(string));   //和生产订单行关联
            table.Columns.Add("OpSeq", typeof(string));
            table.Columns.Add("ComponentId", typeof(int));
            table.Columns.Add("BaseQtyN", typeof(decimal));
            table.Columns.Add("BaseQtyD", typeof(decimal));
            table.Columns.Add("qty", typeof(decimal));
            //辅助计量单位，件数、换算率，上级生产订单数量
            //AuxUnitCode,ChangeRate,AuxBaseQtyN,AuxQty,UpperMoQty 
            table.Columns.Add("AuxUnitCode", typeof(string));
            table.Columns.Add("ChangeRate", typeof(decimal));
            table.Columns.Add("AuxBaseQtyN", typeof(decimal));
            table.Columns.Add("AuxQty", typeof(decimal));
            table.Columns.Add("UpperMoQty", typeof(decimal));
            table.Columns.Add("InvCode", typeof(string));
            table.Columns.Add("OpComponentId", typeof(int));
            table.Columns.Add("iWIPtype", typeof(int));
            table.Columns.Add("cWhCode", typeof(string));
            table.Columns.Add("cbatch", typeof(string));
            return table;


            //cSource,SoDId,SoType,iMrpsid,csocode,irowno
        }

        public static int[] GetIDOnTransaction(string RemoteId, string cAccount, string cVouchType, int iAmount, SqlTransaction tran)
        {
            //string cAcc_Id = cAccount.Substring(7, 3);
            SqlCommand myCommand = new SqlCommand("sp_GetId", tran.Connection, tran);
            myCommand.CommandType = CommandType.StoredProcedure;

            //添加存储过程输入输出参数类型及输入参数值
            myCommand.Parameters.Add("@RemoteId", SqlDbType.VarChar, 2).Value = RemoteId;
            myCommand.Parameters.Add("@cAcc_Id", SqlDbType.VarChar, 3).Value = cAccount; //U8帐套号
            myCommand.Parameters.Add("@cVouchType", SqlDbType.VarChar, 50).Value = cVouchType;
            myCommand.Parameters.Add("@iAmount", SqlDbType.Int).Value = iAmount;        //需要处理明细 记录数
            myCommand.Parameters.Add("@iFatherId", SqlDbType.Int);
            myCommand.Parameters.Add("@iChildId", SqlDbType.Int);
            //输入参数
            myCommand.Parameters["@RemoteId"].DbType = DbType.String;
            myCommand.Parameters["@RemoteId"].Direction = ParameterDirection.Input;
            myCommand.Parameters["@cAcc_Id"].DbType = DbType.String;
            myCommand.Parameters["@cAcc_Id"].Direction = ParameterDirection.Input;
            myCommand.Parameters["@cVouchType"].DbType = DbType.String;
            myCommand.Parameters["@cVouchType"].Direction = ParameterDirection.Input;
            myCommand.Parameters["@iAmount"].DbType = DbType.Int32;
            myCommand.Parameters["@iAmount"].Direction = ParameterDirection.Input;
            //输出参数
            myCommand.Parameters["@iFatherId"].DbType = DbType.Int32;
            myCommand.Parameters["@iFatherId"].Direction = ParameterDirection.Output;
            myCommand.Parameters["@iChildId"].DbType = DbType.Int32;
            myCommand.Parameters["@iChildId"].Direction = ParameterDirection.Output;

            //执行存储过程 此处类似于查询语句
            myCommand.ExecuteScalar();

            //接受执行存储过程后的返回值
            int FatherId = (int)myCommand.Parameters["@iFatherId"].Value;   //主表ID
            int ChildId = (int)myCommand.Parameters["@iChildId"].Value;     //子表ID

            int[] getID = new int[2];
            getID[0] = FatherId;
            getID[1] = ChildId;
            return getID;
        }

        public static int UpdateBarcode(WMS_BARCODE model)
        {
            StringBuilder SQL = new StringBuilder();
            SQL.Append(" update [WMS_BARCODE] set ");
            SQL.AppendFormat(" [IQTY] = {0} ", model.IQTY);
            //if (model.bLeaveInvalid == 1)
            //{
            //    SQL.AppendFormat(" ,[CSTATE] = '{0}' ", "已出库");
            //}
            SQL.AppendFormat(" where [BARCODENO] = '{0}' ", model.BARCODENO);

            int res = DbHelper2.ExecuteNonQuery(SQL.ToString(), CanShu.conStr);
            if (res == 0)
            {
                ExLog.WriteTxt("条码更新失败:\r\n" + SQL.ToString());
            }
            return res;
        }

    }
}
